import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.Point2D;
import java.util.Vector;

import javax.swing.JFrame;


@SuppressWarnings("serial")
public class Frame extends JFrame {
	
	Vector<Shape> shapes;
	
	public Frame(){
		shapes = new Vector<Shape>();
		setSize(500,500);
	}
	
	public void addShape(Shape s){
		shapes.add(s);
	}
	
	public void removeShape(Shape s){
		shapes.remove(s);
	}
	
	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		g.translate(250, 250);
		for (Shape s : shapes){
			if (s instanceof Line){
				Line line = ((Line)s);
				Polygon p = line.getPolygon();
				for (int i = 0 ; i < p.ypoints.length ; i++){
					p.ypoints[i] = - p.ypoints[i];
				}
				g2.drawPolygon(p);
				
			} else if (s instanceof Cone){
				Cone cone = ((Cone) s);
				int radius = (int)cone.getRadius();
				Point2D.Double origin = cone.getOrigin();
				
				Point2D.Double p1 = cone.getP1();
				Point2D.Double p2 = cone.getP2();
				g2.drawArc((int)origin.x - radius , -(int)origin.y - radius, radius*2, radius*2, (int)cone.getStartAngle(), (int)cone.getAngle());
				g2.drawLine((int)origin.x, -(int)origin.y, (int)p1.x, -(int)p1.y);
				g2.drawLine((int)origin.x, -(int)origin.y, (int)p2.x, -(int)p2.y);
			} else if (s instanceof Circle){
				int radius = (int)((Circle) s).getRadius();
				g2.drawOval((int)s.getOrigin().x - radius , -(int)s.getOrigin().y - radius, radius*2, radius*2);
				
			}
		}
	}

}
